using SharpDX;
using SharpDX.Direct3D11;
using System;

namespace Engine.Graphics.Shaders.C11UndercoverShaders
{
    internal class Material208 : ShaderBaseC11Undercover, ISetShaderValues
    {
        #region Private Fields

        private Texture2D envTexture;
        private int lastBumpTextureID1 = -1;
        private int lastBumpTextureID2 = -1;
        private int lastBumpTextureID3 = -1;
        private uint lastHashcodeMappingMatrix1 = 0;
        private uint lastHashcodeMappingMatrix2 = 0;
        private uint lastHashcodeMappingMatrix3 = 0;
        private int lastTextureID1 = -1;
        private int lastTextureID2 = -1;
        private int lastTextureID3 = -1;
        private string name;

        #endregion Private Fields

        #region Public Constructors

        public Material208(Device renderDevice, string shaderDirectory)
            : base(renderDevice)
        {
            this.name = shaderDirectory;

            //            ShaderFlags shaderflags;
            //#if DEBUG
            //            shaderflags = ShaderFlags.Debug | ShaderFlags.SkipOptimization;
            //#else
            //            shaderflags = ShaderFlags.OptimizationLevel3;
            //#endif

            //            this.effect = Effect.FromFile(renderDevice, shaderDirectory + "\\material208.fx", null, null, null, shaderflags, effectPool);
            //            this.envTexture = Texture.FromFile(renderDevice, shaderDirectory + "envCube.dds", Usage.None, Graphic.DefaultPool);
            //            this.effect.SetTexture("TexEnvMapTex", this.envTexture);
        }

        #endregion Public Constructors

        #region Public Properties

        public ShaderBase Effect
        {
            get { return this.effect; }
        }

        public string Name
        {
            get
            {
                return this.name;
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        #endregion Public Properties

        #region Public Methods

        public new void Dispose()
        {
            base.Dispose(); ;
        }

        public void SetEnvirementTexture(ShaderResourceView texture)
        {
            // this.effect.SetTexture("SunCol", texture);
        }

        public void SetFogColor(SharpDX.Color4 color)
        {
            //  this.effect.SetValue("FogCol", color);
        }

        public void SetFogDistanceStartEnd(float start, float end)
        {
            // this.effect.SetValue("fogStart", start);
            // this.effect.SetValue("fogEnd", end);
        }

        public void SetLightDirection(SharpDX.Vector3 direction)
        {
            // this.effect.SetValue("LightVec", new Vector4(direction.X, direction.Y, direction.Z, 1.0f));
        }

        public void SetModulate(float value)
        {
            //this.effect.SetValue("modulate", value);
        }

        public void SetProperties(int materialID, MaterialManager materialManager)
        {
            Material material = materialManager.GetMaterial(materialID);

            short TextureID1 = materialManager.GetTextureIDTexture1(materialID);
            short TextureID2 = materialManager.GetTextureIDTexture2(materialID);
            short TextureID3 = materialManager.GetTextureIDTexture3(materialID);
            short BumpTextureID1 = materialManager.GetTextureIDBumbTexture1(materialID);
            short BumpTextureID2 = materialManager.GetTextureIDBumbTexture2(materialID);
            short BumpTextureID3 = materialManager.GetTextureIDBumbTexture3(materialID);

            this.lastTextureID1 = -1;
            this.lastTextureID2 = -1;
            this.lastTextureID3 = -1;
            this.lastBumpTextureID1 = -1;
            this.lastBumpTextureID2 = -1;
            this.lastBumpTextureID3 = -1;

            //base.SetSamplerState(samplerState, 0);
            //base.SetSamplerState(null, 1);
            //base.SetSamplerState(samplerState, 2);
            //base.SetSamplerState(null, 3);
            //base.SetSamplerState(samplerState, 4);
            //base.SetSamplerState(null, 5);
            base.SetTextureUvMatrix(material);

            //effect.SetValue("paintHighLines", false);
            if (this.lastTextureID1 != TextureID1)
            {
                this.lastTextureID1 = TextureID1;

                base.SetTexture(0, material.GetTexture1(materialManager));
                base.SetTexture(1, material.GetBumpTexture1(materialManager));
            }

            if (this.lastTextureID2 != TextureID2)
            {
                this.lastTextureID2 = TextureID2;

                base.SetTexture(2, material.GetTexture2(materialManager));
                base.SetTexture(3, material.GetBumpTexture2(materialManager));
            }
            if (this.lastTextureID3 != 3)
            {
                this.lastTextureID3 = TextureID3;

                base.SetTexture(4, material.GetTexture3(materialManager));
                base.SetTexture(5, material.GetBumpTexture3(materialManager));
            }
        }

        public void SetSunLight(SharpDX.Color4 color)
        {
            //  this.effect.SetValue("SunColor", color);
        }

        public void SetWorldInverseTranspose(SharpDX.Matrix matrix)
        {
            //this.effect.SetValue("worldInverseTranspose", matrix);
        }

        public void UpdateValues(SharpDX.Matrix worldViewProj, SharpDX.Matrix world, Matrix WorldViewMtx, SharpDX.Vector3 cameraPosition)
        {
            //this.effect.SetValue("CameraPos", new Vector4(cameraPosition.X, cameraPosition.Y, cameraPosition.Z, 1.0f));
            //this.effect.SetValue("WorldViewProjMtx", worldViewProj);
            //this.effect.SetValue("WorldViewMtx", WorldViewMtx);
        }

        #endregion Public Methods
    }
}